<?php

namespace app\store\controller;

use app\store\service\LoginService;
use app\store\service\OrderService;
use app\store\service\SampleOrderService;
use app\BaseController;
use app\Response;
use think\facade\Request;

class Order extends BaseController
{
    /** 订单列表
    */
    public function orderList(){
        if (Request::isPost()) {
            $user_id = LoginService::getUserIdFromToken();
            if (!is_numeric($user_id)) {
                return $user_id;
            }
            $page = Request::post("page",1);
            $num = Request::post("num",10);
            $state = Request::post("state","");
            $type = Request::post("type",2);
            $info = OrderService::orderListService($user_id,$page,$num,$state,$type);
            return $info;
        }
    }



    public function orderInfo(){
        if (Request::isPost()) {
            $user_id = LoginService::getUserIdFromToken();
            if (!is_numeric($user_id)) {
                return $user_id;
            }
            $id = Request::post("id");
            if(empty($id)){
                return Response::wrapError(0,"参数异常!");
            }
            $res = OrderService::orderInfoService($id,$user_id);
            return $res;
        }
    }

    public function ewmOrderInfo(){
        if (Request::isPost()) {
            $user_id = LoginService::getUserIdFromToken();
            if (!is_numeric($user_id)) {
                return $user_id;
            }
            $data = Request::post("ewm_data");
            $res = OrderService::ewmOrderInfoService($user_id,$data);
            return $res;
        }
    }

    /*** 订单确认收货
    */
    public function orderReceive(){
        if (Request::isPost()) {
            $user_id = LoginService::getUserIdFromToken();
            if (!is_numeric($user_id)) {
                return $user_id;
            }
            $id = Request::post("id");
            if(empty($id)){
                return Response::wrapError("订单信息获取异常!");
            }
            $res = OrderService::orderReceiveService($user_id,$id);
            return $res;
        }
    }



}